<?php
// +----------------------------------------------------------------------
// | 公用模型
// +----------------------------------------------------------------------
// | Author: 李乾坤 <261001642@qq.com>
// +----------------------------------------------------------------------
class CommonModel extends Model {

	// 获取当前用户的ID
    public function getMemberId() {
        return isset($_SESSION[C('USER_AUTH_KEY')])?$_SESSION[C('USER_AUTH_KEY')]:0;
    }
	public function checkTitle($title=null,$id=null) {
        $title=is_null($title) ? $_POST['title'] : $title;
        $id=is_null($id) ? $_POST['id'] : $id;
        if(is_string($title)) {
            $map['title']	 =	 $title;
            if(!empty($id)) {
                $map['id']	=	array('neq',$id);
            }
            $result	=	$this->where($map)->count('id');
            if($result>0) {
                return false;
            }else{
                return true;
            }
        }
        return true;
	}
	public function checkName($name=null,$id=null) {
        $name=is_null($name) ? $_POST['name'] : $name;
        $id=is_null($id) ? $_POST['id'] : $id;
        if(is_string($name)) {
            $map['title']	 =	 $name;
            if(!empty($_POST['id'])) {
                $map['id']	=	array('neq',$id);
            }
            $result	=	$this->where($map)->count('id');
            if($result>0) {
                return false;
            }else{
                return true;
            }
        }
        return true;
	}

}
?>